package tree;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class sortedArrayToBST {
    public TreeNode sortedArrayToBST(int[] nums) {
        int len = nums.length;
        if (len == 0){
            return null;
        }
        return ArrayToBST(nums, 0, nums.length);
    }
    public TreeNode ArrayToBST(int[] nums, int begin, int end){
        if (begin >= end){
            return null;
        }
        int mid = (begin + end) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = ArrayToBST(nums, begin, mid);
        root.right = ArrayToBST(nums, mid + 1, end);
        return root;
    }
}
